// import { DataTypes } from "sequelize";
//
// import sequelize from "../db/index.js";
// import { crpytPassword } from "../utils/crypt.js";

const sequelize = require('../connection');
const { DataTypes } = require("sequelize");

const Users = sequelize.define(
    "Users",
    {
        user_id: {
            type: DataTypes.INTEGER,
            primaryKey: true,
            allowNull: true,
            autoIncrement: true
        },
        userName: {
            type: DataTypes.STRING,
            unique: true,
            allowNull: false,
            comment: "用户名",
        },
        password: {
            type: DataTypes.STRING,
            allowNull: false,
            comment: "密码",
            // set(val) {
            //     this.setDataValue("password", crpytPassword(val));
            // },
        },
        gender: {
            type: DataTypes.STRING,
            allowNull: false,
            defaultValue: '未知',
            comment: "男女",
        },
        role: {
            type: DataTypes.STRING,
            allowNull: false,
            defaultValue: '用户',
            comment: "是否为管理员 1是 0不是",
        },
    },
    {
        timestamps: false,
        tableName: 'users'
    }
);

module.exports = Users;
